<template>
    <div class="password-check-container">
        <div class="password-check-box">
            <h2>Password Strength: <span class="password-check-text" :style="{color:gradientColor}">{{ strengthText }}</span></h2>
            <div class="password-strength" :style="{backgroundImage:bgColor}"></div>
            <input type="password" class="password-input" placeholder="Enter your password" v-model="password">
        </div>
    </div>
</template>

<script>

export default {
    name: "PasswordCheckInput",
    data() {
        return {
            password: "",
        }
    },
    computed: {
        degree() {
            let strength = Math.min(this.password.length, 12);
            return strength * 30;
        },
        gradientColor() {
            let strength = Math.min(this.password.length, 12);
            if (strength===0){
                return "#fff";
            }
            return strength <= 4 ? "#ff2c1c" : (strength <= 8 ? "#ff9800" : "#12ff12");
        },
        strengthText() {
            let strength = Math.min(this.password.length, 12);
            if (strength===0){
                return "Check";
            }
            return strength <= 4 ? "Weak" : (strength <= 8 ? "Medium" : "Strong");
        },
        bgColor(){
            let strength = Math.min(this.password.length, 12);
            if (strength===0){
                return "#115";
            }
            let gradientColor=strength <= 4 ? "#ff2c1c" : (strength <= 8 ? "#ff9800" : "#12ff12");
            let degree=strength * 30;
            return "conic-gradient("+gradientColor +" "+ degree+"deg,#1115 "+degree+"deg)";
        },
    },
}
</script>

<style scoped>
.password-check-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.password-check-box {
    position: relative;
    width: 300px;
    height: 50px;
}

.password-check-box>h2 {
    position: absolute;
    top: -40px;
    font-size: 1.25em;
    color: #fff;
    font-weight: 500;
}

.password-input {
    position: absolute;
    inset: 2px;
    z-index: 10;
    font-size: 1em;
    border: none;
    outline: none;
    padding: 10px 15px;
    background-color: #333;
    color: #fff;
}

.password-strength {
    position: absolute;
    inset: 0;
    filter: blur(10px);
}

</style>
